package cn.iocoder.devlop.module.annual.report.subcapital.controller.app;

import cn.iocoder.devlop.framework.common.pojo.CommonResult;
import cn.iocoder.devlop.module.annual.report.subcapital.controller.vo.SubcapitalOverwriteVO;
import cn.iocoder.devlop.module.annual.report.subcapital.controller.vo.SubcapitalRespVO;
import cn.iocoder.devlop.module.annual.report.subcapital.convert.SubcapitalConvert;
import cn.iocoder.devlop.module.annual.report.subcapital.dal.dataobject.SubcapitalDO;
import cn.iocoder.devlop.module.annual.report.subcapital.service.SubcapitalService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static cn.iocoder.devlop.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 APP - 年报股东及出资")
@RestController
@RequestMapping("/annual/report/subcapital")
@Validated
public class AppSubcapitalController {

    @Resource
    private SubcapitalService subcapitalService;

    @GetMapping("/list")
    @Operation(summary = "获得年报股东及出资")
    public CommonResult<List<SubcapitalRespVO>> getSubcapitalList(@RequestParam("regno") String regno, @RequestParam("ancheyear") String ancheyear) {
        List<SubcapitalDO> list = subcapitalService.getSubcapitalList(regno, ancheyear);
        return success(SubcapitalConvert.INSTANCE.convertList(list));
    }

    @PutMapping("/overwrite")
    @Operation(summary = "覆盖更新年报股东及出资")
    public CommonResult<Boolean> overwriteSubcapital(@Valid @RequestBody SubcapitalOverwriteVO updateReqVO) {
        subcapitalService.overwriteSubcapital(updateReqVO);
        return success(true);
    }

}
